package com.iting.xmldemo.factorybeandemo;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;

/**
 * @author iting Nie
 * @version 1.1
 * @create 2021/12/11
 */
public class CarFactory implements FactoryBean<Car> , DisposableBean {

	private String carData;

	public void setCarData(String carData) {
		this.carData = carData;
	}

	public CarFactory() {
		// System.out.println("CarFactory的无参构造");
	}

	@Override
	public Car getObject() throws Exception {
		// System.out.println("调用了CarFactory中的getObject方法");
		String[] split = carData.split(",");
		String name = split[0];
		String price = split[1];
		Car car = new Car(name, price);
		return car;
	}

	@Override
	public Class<?> getObjectType() {
		return Car.class;
	}

	@Override
	public boolean isSingleton() {
		return true;
	}

	public void add(){
		System.out.println("CarFactory中的add方法执行了");
	}


	@Override
	public void destroy() throws Exception {
		System.out.println("CarFactory的destroy");
	}
}
